
const { ccclass, property } = cc._decorator;

@ccclass
export default class FYBatchParent extends cc.Component {
    /** 激活回调 */
    private CBActiveChange = null;
    /** 位置变化回调 */
    private CBPositionChange = null;
    /** 角度变化回调 */
    private CBRotationChange = null;
    /** 销毁回调 */
    private CBDestroy = null;


    public init(cbActiveChange: Function = null, cbPositionChange: Function = null, cbRotationChange = null, cbDestroy: Function = null) {
        this.CBActiveChange = cbActiveChange;
        this.CBPositionChange = cbPositionChange;
        this.CBDestroy = cbDestroy;

        if (this.CBPositionChange) {
            this.node.on(cc.Node.EventType.POSITION_CHANGED, this.CBPositionChange);
        }
        if (this.CBRotationChange) {
            this.node.on(cc.Node.EventType.ROTATION_CHANGED, this.CBRotationChange);
        }
    }

    public removeMsg() {
        if (this.CBPositionChange) {
            this.node.off(cc.Node.EventType.POSITION_CHANGED, this.CBPositionChange);
        }
    }

    onEnable() {
        if (this.CBActiveChange) {
            this.CBActiveChange(true);
        }
    }

    onDisable() {
        if (this.CBActiveChange) {
            this.CBActiveChange(false);
        }
    }

    onDestroy() {
        if (this.CBDestroy) {
            this.CBDestroy();
        }
    }
}
